﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Data.Repositories;
using Domain;
using Domain.Entities;
using Service;

namespace Web.Controllers
{
    public class ProductController : Controller
    {
        private readonly IProductsService<Product, PageData<Product>> _productService;
        public ProductController(IProductsService<Product, PageData<Product>> productService)
        {
            this._productService = productService;
        }

        public ViewResult List()
        {
            var list = _productService.GetAll();
            return View(list);
        }

        public ViewResult Add()
        {
            Product p = new Product();
            p.Name = "E";
            p.Description = "E_Desc";
            p.Category = "2";
            _productService.Add(p);

            var list = _productService.GetAll();
            return View(list);
        }

        public ViewResult Update()
        {
            Product p = _productService.GetById(1);
            p.Price = 50;
            p.Description = "1Price";
            _productService.Update(p);
            //_productService.Commit();
            var list = _productService.GetAll();
            return View(list);
        }
        public ViewResult Delete()
        {
            Product p = _productService.GetById(5);
            _productService.Delete(p);

            var list = _productService.GetAll();
            return View(list);
        }




    }
}
